//
//  SEGPublishPGCViewModel.m
//  Commom
//
//  Created by 梁学彰 on 2020/6/13.
//

#import "SEGPublishPGCViewModel.h"
#import "SEGCommunitySocialManager.h"

@implementation SEGPublishPGCViewModel
- (instancetype)initWithPGCModel:(SEGPictorialDetailModel *)model {
    if (self = [super init]) {
        _model = model;
    }
    return self;
}



- (RACSignal *)seg_shareToNeighbourhoodWithString:(NSString *)content {
    @weakify(self);
    RACSignal *signal = [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
        @strongify(self);
        
        SEGProfileModel* /*SAM:登录*/ sysAccount = [SEGProfileManager sharedManager].profile /*SAM:登录FUNC*/;
        
        NSDictionary* params = [NSDictionary dictionaryWithObjectsAndKeys:
                                self.model.pictorialId, @"objId",
                                self.model.type, @"objType",
                                content, @"quizContent",
                                sysAccount.userId, @"userId",
                                self.model.quizTypeId, @"quizTypeId",
                                @"3", @"quizRangeId",
                                sysAccount.cityId, @"regionId", //城市编码
                                sysAccount.jobCommunity, @"communityId", //城市编码
                                sysAccount.jobCommunity, @"organId", //小区id
                                self.model.pictorialId, @"linkUrl",
                                self.model.pictorialTitle, @"linkTitle",
                                @"", @"quizPic", //图片拼接
                                [NSString stringWithFormat:@"来自%@ %@", sysAccount.city, sysAccount.communityName], @"communityName", //城市+名称
                                sysAccount.nickname, @"creator",
                                nil];
        
        SEGCommunitySocialManager *manager = [[SEGCommunitySocialManager alloc] init];
        [manager requestSaveQuizWithParams:params Finished:^(BOOL isSuccessed, NSString *codeType, NSString *errorMessage) {
            if (isSuccessed) {
                [subscriber sendCompleted];
                //积分行为设置（5.0.0 转发pgc也算邻里圈发帖）
                [[SEGAnalyseBehaviorManager sharedManager] requestIntegralGrowthWithCode:SEGIntegralCode.postForHelp module:SEGIntegralModule.neighborhoodCircle businessID:nil finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
                }];
            }else {
                [subscriber sendError:[NSError errorWithDomain:NSURLErrorDomain code:codeType.integerValue userInfo:@{NSLocalizedDescriptionKey:errorMessage}]];
            }
        }];
        
        return nil;
    }];
    return signal;
    
    
}

@end
